import java.util.HashSet;
import java.util.Iterator;

public class HashSetRewrite{
    public static void main(String[] args){
        HashSet<Key> hSet = new HashSet<Key>();
        hSet.add(new Key(1, "aaa"));
        hSet.add(new Key(2, "bbb"));
        hSet.add(new Key(3, "ccc"));
        hSet.add(new Key(1, "ddd"));
        
        System.out.println("size: " + hSet.size());
        
        Iterator iter = hSet.iterator();
        while(iter.hasNext()){
            System.out.println(iter.next());
        }
    }
}

class Key{
    int k;
    String name;
    public Key(int k, String name){
        this.k = k;
        this.name = name;
    }
    
    public int hashCode(){
        return this.k;
    }
    
    public boolean equals(Object o){
        if(this == o){
            return true;
        }
        
        if(o.getClass() == Key.class){
            Key key = (Key)o;
            if(key.k == this.k){
                return true;
            }
        }
        
        return false;
    }
    
    public String toString(){
        return "[ " + k + " : " + name + " ]";
    }
}